package net.dopan.pigframe.demo.service.impl;

import net.dopan.pigframe.core.base.service.impl.BaseServiceImpl;
import net.dopan.pigframe.demo.mapper.UserActivityMapper;
import net.dopan.pigframe.demo.model.entity.UserActivity;
import net.dopan.pigframe.demo.model.entity.vo.PublishNoteTagVo;
import net.dopan.pigframe.demo.model.entity.vo.UserEventVo;
import net.dopan.pigframe.demo.model.entity.vo.UserNoteVo;
import net.dopan.pigframe.demo.service.UserNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class UserNoteServiceImpl extends BaseServiceImpl<UserActivityMapper, UserActivity> implements UserNoteService {

    @Autowired
    private UserActivityMapper userActivityMapper;

    @Override
    public Integer addUserNoteTag(PublishNoteTagVo publishNoteTagVo) {
        return userActivityMapper.addUserNoteTag(publishNoteTagVo);
    }

    @Override
    public List<Map<String, String>> getPublishNoteList(String tagName) {
        return userActivityMapper.getPublishNoteList(tagName);
    }

    @Override
    public Integer addUserNoteMentionUser(String userId, String noteId) {
        String username = userActivityMapper.getUsername(userId);
        return userActivityMapper.addUserNoteMentionUser(userId, noteId, username);
    }

    @Override
    public Integer findUserNoteMaxId() {
        return userActivityMapper.findUserNoteMaxId();
    }

    @Override
    public Integer addUserNoteTags(String noteId, String tagId) {
        return userActivityMapper.addUserNoteTags(noteId, tagId);
    }

    @Override
    public Integer addUserNote(UserNoteVo userNoteVo) {

        userNoteVo.setCollectNum("0");
        userNoteVo.setLikeNum("0");
        userNoteVo.setCommentNum("0");
        /** 1为活动 2 为笔记 */
        userNoteVo.setTypeFlag(2);
        int num = userActivityMapper.addUserNote(userNoteVo);
        /** 添加用户发布笔记动态*/
        UserEventVo userEventVo = new UserEventVo();
        userEventVo.setCreateTime(userNoteVo.getCreateTime());
        userEventVo.setEventMsgId(Long.parseLong(userNoteVo.getNoteId()));
        userEventVo.setEventTypeId(2);
        userEventVo.setUserId(Long.parseLong(userNoteVo.getUserId()));
        userActivityMapper.addUserEvent(userEventVo);
        return num;
    }

    @Override
    public Integer addUserNotePhoto(String noteId, String photoUrl) {
        return userActivityMapper.addUserNotePhoto(noteId, photoUrl);
    }
}
